use "C:\Users\maxwe\OneDrive\desktop\Kasoji\FINIDEXWB 2021.dta" 
gen internet = internetaccess
ta internet
replace internet =2 if internet==3
replace internet =0 if internet==2
gen  paymnets = receive_wages
ta paymnets
ta receive_transfers
replace paymnets = 4 if paymnets==2
replace paymnets = 4 if paymnets==5
replace paymnets = 1 if paymnets==3
gen digital_utilitypay = pay_utilities
ta digital_utilitypay
replace digital_utilitypay =4 if digital_utilitypay ==2
replace digital_utilitypay =1 if digital_utilitypay ==3
replace digital_utilitypay =4 if digital_utilitypay ==5
gen mobile_ownership = mobileowner
ta mobile_ownership
replace mobile_ownership=0 if mobile_ownership==2
ta receive_wages
gen employment_status = emp_in
ta employment_status
replace employment_status =0 if employment_status ==2
gen wages = receive_wages
ta wages
replace wages =1 if wages==2
replace wages =1 if wages==3
replace wages =4 if wages==5
replace wages =0 if wages==4
ta receive_agriculture
gen Agric_sales = receive_agriculture
ta Agric_sales
replace Agric_sales =1 if Agric_sales==2
replace Agric_sales =1 if Agric_sales==3
replace Agric_sales =4 if Agric_sales==5
replace Agric_sales =0 if Agric_sales==4
ta fin9
ta remittances
gen remittences_receive = remittances
replace remittences_receive= 1 if remittences_receive ==2
replace remittences_receive= 1 if remittences_receive ==3
replace remittences_receive= 1 if remittences_receive ==4
replace remittences_receive= 5 if remittences_receive ==6
replace remittences_receive= 0 if remittences_receive ==5
psmatch2  internet  female age educ inc_q remittences_receive urbanicity_f2 employment_status mobile_ownership , outcome ( saved ) neighbor(3)
bootstrap:psmatch2  internet  female age educ inc_q remittences_receive urbanicity_f2 employment_status mobile_ownership , outcome ( saved ) neighbor(3)
psmatch2  internet  female age educ inc_q emp_in urbanicity_f2f , outcome ( borrowed ) neighbor(3)logit
teffects ipwra ( account    educ inc_q emp_in urbanicity_f2f ,probit) (internet  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
tebalance summarize
tebalance overid, nolog

/////////////////////////////////////////rabound 
pscore internet female age educ inc_q emp_in urbanicity_f2f ,  pscore(myscore) logit
psmatch2 internet , outcome( saved ) pscore( myscore)
gen delta = saved - saved if - internet ==1 &_support==1
rbounds delta, gamma(1(1)3)

///////////////////////////// Heckman 2 step and IPWR 
teffects ipwra ( saved   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
gen formal_saving = fin17a
replace formal_saving =0 if formal_saving ==2
gen mobile_saving = fin17a1
replace mobile_saving =0 if mobile_saving ==2
gen Informal_saving = fin17b
replace Informal_saving =0 if Informal_saving ==2
gen location = urbanicity_f2f
replace location =0 if location ==2
ttest age, by (internet)
ttest female , by (internet)
gen Sex = female
tab Sex
replace Sex =0 if Sex==2
ttest Sex , by (internet)
ttest remittences_receive , by (internet)
ttest location , by (internet)
ttest educ , by (internet)
ttest employment_status , by (internet)
ttest inc_q , by (internet)
ttest Informal_saving , by (internet)
ttest mobile_saving , by (internet)
ttest formal_saving , by (internet)
ttest old_agesave , by (internet)
ttest save , by (internet)
teffects ipwra ( mobile_saving    educ inc_q emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
ttest mobileowner , by (internet)
ttest mobile_ownership , by (internet)
treatreg  internet (  remittences_receive  female age educ inc_q emp_in urbanicity_f2f),  treat( saved =    educ inc_q emp_in urbanicity_f2f  ) twostep
treatreg saved  (  remittences_receive  Sex age educ inc_q emp_in location ),  treat( internet = age   educ inc_q emp_in urbanicity_f2f mobile_ownership Sex remittences_receive location ) twostep
treatreg saved  (  remittences_receive  Sex age educ inc_q emp_in location ),  treat( internet = age   educ inc_q emp_in  mobile_ownership Sex remittences_receive location ) twostep
treatreg saved  (  remittences_receive  Sex age educ inc_q emp_in location ),  treat( internet = age   educ inc_q emp_in  mobile_ownership Sex remittences_receive location )


teffects ipwra ( saved   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
teffects ipwra ( saved   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive mobile_ownership female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
teffects ipwra ( saved   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
su employment_status
teffects ipwra ( saved   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
teffects ipwra ( formal_saving   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations
replace Informal_saving =1 if Informal_saving==4
teffects ipwra ( Informal_saving   educ  emp_in urbanicity_f2f ,probit) (internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f, probit), atet nolog aequations




















foreach var of varlist internet remittences_receive  female age educ inc_q emp_in urbanicity_f2f{
tebalance density `var', saving("$output\balance_`var'", replace)
foreach var of varlist   female age educ inc_q emp_in urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
 foreach var of varlist age educ inc_q emp_in urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
 foreach var of varlist  educ inc_q emp_in urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
 foreach var of varlist inc_q emp_in urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
 foreach var of varlist emp_in urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
 foreach var of varlist urbanicity_f2f{
. tebalance density `var', saving("$output\balance_`var'", replace)
.                      }
